<?php

namespace App\Http\Controllers\BK;

use App\Http\Requests\BK\Admin\RoleIndexRequest;
use App\Http\Requests\BK\Admin\RoleStoreRequest;
use App\Http\Requests\BK\Admin\RoleUpdateRequest;
use App\Services\RoleService;
use App\Http\Controllers\Controller;

class RoleController extends Controller
{
    public function __construct()
    {
        $this->middleware(['auth:admins']);
    }
    /**
     * Description:角色列表
     * @param RoleIndexRequest $request
     * @param RoleService $roleService
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(RoleIndexRequest $request,RoleService $roleService)
    {
        return success($roleService->getIndex($request->all()));
    }

    /**
     * Description:新增角色
     * @param RoleStoreRequest $request
     * @param RoleService $roleService
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\GeneralException
     */
    public function store(RoleStoreRequest $request,RoleService $roleService)
    {
        return success($roleService->storeRole($request->all()));
    }

    /**
     * 修改角色
     * @param RoleUpdateRequest $request
     * @param RoleService $roleService
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\GeneralException
     */
    public function update(RoleUpdateRequest $request,RoleService $roleService)
    {
        return success($roleService->updateRole($request->all()));
    }

    /**
     * Description:删除角色
     * @param int $id
     * @param RoleService $roleService
     * @return \Illuminate\Http\JsonResponse
     * @throws \Exception
     */
    public function destroy(int $id,RoleService $roleService)
    {
        return success($roleService->destroyRole($id));
    }

    /**
     * Description:查看角色
     * @param int $id
     * @param RoleService $roleService
     * @return \Illuminate\Http\JsonResponse
     */
    public function show(int $id,RoleService $roleService)
    {
        return success($roleService->showRole($id));
    }
}
